package com.cmpe.av.androidservice;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cmpe.av.logic.ReportLogic;
import com.cmpe.av.model.ObstacleType;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * Servlet implementation class GetObstacles
 */
@WebServlet("/GetObstacles")
public class GetObstacles extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
	private List<ObstacleType> obstacles;
    public GetObstacles() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		obstacles = getObstacles();
		ObjectMapper mapper = new ObjectMapper();
		response.getWriter().write(mapper.writeValueAsString(obstacles));
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
	public List<ObstacleType> getObstacles(){
		ReportLogic msAccess;
		obstacles= new ArrayList<ObstacleType>();
		try{
			msAccess = new ReportLogic();
			obstacles=msAccess.getObstacles();
		}
		catch(Exception e){
			System.out.println(e);
		}
		return obstacles;
	}

}
